package dao;
import java.sql.*;

import bean.DBConnectionManager;
import vo.Manager;
public class LoginDao {
	private Connection conn;
	private PreparedStatement ps=null;
	private ResultSet rs=null;
	//用户登录login()
	public String login(String username,String password,int role) throws Exception{
		conn=DBConnectionManager.getConnection();
		if(role==1){
			String sql="select * from t_manager";
			ps=conn.prepareStatement(sql);
			rs=ps.executeQuery();
			if(rs.next()){
				String pass=rs.getString("MANPWD");
				if(pass.equals(password)){
					return "managerSuccess";
					
				}else{
					return "managerFailed";
				}
			}else{
				return "managerFailed";
			}
		}else if(role==2){
			String sql="select * from t_teacher";
			ps=conn.prepareStatement(sql);
			rs=ps.executeQuery();
			if(rs.next()){
				String pass=rs.getString("TEAPWD");
				if(pass.equals(password)){
					return "teacherSuccess";
					
				}else{
					return "teacherFailed";
				}
			}else{
				return "teacherFailed";
			}
		}else if(role==3){
			String sql="select * from t_student";
			ps=conn.prepareStatement(sql);
			rs=ps.executeQuery();
			if(rs.next()){
				String pass=rs.getString("STUPWD");
				if(pass.equals(password)){
					return "studentSuccess";
					
				}else{
					return "studentFailed";
				}
			}else{
				return "studentFailed";
			}
		}
		return "back";
	}
}
